home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE07 / FILES / NETLOCK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-01-22  |  2.2 KB  |  75 lines

  1. unit NetLock;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinTypes;
  7.  
  8. { Core routine that mimics Win32 parameter set }
  9. function LockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
  10.                   LockBytesLow, LockBytesHigh: Integer): Bool;
  11. { Handle based routine that un/locks a given number of bytes }
  12. function LockFileArea(Handle: Integer; FileOffset, LockBytes: Longint;
  13.                       Unlock: Boolean): Bool;
  14. { File variable based routine that un/locks a given number of records }
  15. function LockFileVarArea(var FileVar; RecordNumber, NumRecords: Longint;
  16.                          Unlock: Boolean): Bool;
  17. { File variable based routine that un/locks one record }
  18. function LockFileVar(var FileVar; RecordNumber: Longint;
  19.                      Unlock: Boolean): Bool;
  20.  
  21. implementation
  22.  
  23. uses
  24.   SysUtils, WinProcs;
  25.  
  26. const
  27.   LockSpecifier: Byte = 0;
  28.  
  29. { Core routine that mimics Win32 parameter set }
  30. function LockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
  31.   LockBytesLow, LockBytesHigh: Integer): Bool; assembler;
  32. asm
  33.   mov ah, $5C
  34.   mov al, LockSpecifier
  35.   mov bx, Handle
  36.   mov cx, FileOffsetHigh
  37.   mov dx, FileOffsetLow
  38.   mov si, LockBytesHigh
  39.   mov di, LockBytesLow
  40.   int $21
  41.   jnc @1
  42.   xor ax, ax
  43.   jmp @2
  44.  @1:
  45.   mov ax, 1
  46.  @2:
  47. end;
  48.  
  49. { Handle based routine that un/locks a given number of bytes }
  50. function LockFileArea(Handle: Integer; FileOffset, LockBytes: Longint;
  51.                       Unlock: Boolean): Bool;
  52. begin
  53.   LockSpecifier := Byte(Unlock);
  54.   Result := LockFile(Handle, LoWord(FileOffset),
  55.     HiWord(FileOffset), LoWord(LockBytes), HiWord(LockBytes));
  56. end;
  57.  
  58. { File variable based routine that un/locks a given number of records }
  59. function LockFileVarArea(var FileVar; RecordNumber, NumRecords: Longint;
  60.                          Unlock: Boolean): Bool;
  61. begin
  62.   with TFileRec(FileVar) do
  63.     Result := LockFileArea(Handle, Recordnumber * RecSize,
  64.                            NumRecords * RecSize, Unlock);
  65. end;
  66.  
  67. { File variable based routine that un/locks one record }
  68. function LockFileVar(var FileVar; RecordNumber: Longint;
  69.                         Unlock: Boolean): Bool;
  70. begin
  71.   Result := LockFileVarArea(FileVar, RecordNumber, 1, Unlock);
  72. end;
  73.  
  74. end.
  75.